package com.neudu.yiyang.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class TokenUtils {
    @Resource
    RedisUtils redisUtils;

    public String getToken(){
        String token = JWT.create()
                .withExpiresAt(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 3))
                .sign(Algorithm.HMAC256("1231321321564654"));
        redisUtils.set(token, "user");
        redisUtils.expire(token,FLAGS.REDIS_OUTOF_TIME);//seconds
        return token;
    }
}
